KitePlayerMediaSession

class KitePlayerMediaSession(player: KitePlayer, context: Context, tag: String = "KitePlayer", skipInterval: Duration = 15.seconds) : AutoCloseable

Mirrors player into Android's media session and routes the buttons back.

That session is what the lock screen, the headset buttons, the car and the media area of the quick settings panel all read. Building one is what every application was writing by hand.

Most apps get one from KitePlayer.attachMediaSession, which also adds the media notification, background handling and audio focus, and closes it all with the player. Built with this constructor, the session is only the session, and the app closes it with the player.

A button press that arrives after the player closed does nothing.

Parameters

skipInterval

how far the skip back and skip forward buttons move, on the lock screen, the notification, a headset and a car. Positive.

Constructors

Link copied to clipboard
constructor(player: KitePlayer, context: Context, tag: String = "KitePlayer", skipInterval: Duration = 15.seconds)

Properties

Link copied to clipboard
val isAvailable: Boolean = true

Always true here. Other platforms answer false when they have no session, so one check works everywhere.

Link copied to clipboard

The token a Notification.MediaStyle needs.

Functions

Link copied to clipboard
open override fun close()

Closes what this session owns, newest first, then the session itself. Only the first call does anything.

Link copied to clipboard
fun setArtwork(image: Bitmap?)

The picture the session shows, over the item's own cover, which shows when this is null and no loader gives one (#425). A loader set with setArtworkLoader replaces it when the media item changes. A picture larger than the system draws it is scaled down once to that size.

Link copied to clipboard
fun setArtworkLoader(loader: suspend (PlayerSnapshot) -> Bitmap??)

Loads the picture for each media item, so the application does not have to watch the player.

Link copied to clipboard
fun setCustomActions(actions: List<MediaNotificationAction>, onAction: (id: String) -> Unit)

Buttons of the application's own, such as a like or a shuffle button, in the order given.

Link copied to clipboard

The activity to open from the system media controls, usually the player screen. The media notification sets its content intent here too.